<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2024/4/22
 * Time: 17:17
 */

namespace app\controller\index\novel;


use app\controller\index\BaseController;
use app\exception\IndexException;
use app\logic\index\novel\NovelLogic;
use support\Request;
use support\Response;

class IndexController extends BaseController
{
    public $noLogin = ['getList','getBusinessList','getHotsSearchWord'];

    public function getList(Request $request):Response
    {
        $param = [];
        $param['business_id']  = $request->input('business_id');
        $param['order_field'] = $request->input('order_field');
        $param['order_type'] = $request->input('order_type','desc');
        $param['keyword'] = $request->input('keyword');
        $param['spread_type'] = $request->input('spread_type',1);

        $data = NovelLogic::getInstance()->getList($param);
        return $this->endSuccess($data);
    }

    public function getBusinessList(Request $request):Response
    {
        $param = [];
        $param['spread_type'] = $request->input('spread_type',1);
        $data = NovelLogic::getInstance()->getBusinessList($param);
        return $this->endSuccess($data);
    }

    public function getCooperateLink(Request $request):Response
    {
        $param = [];
        $param['novel_sn'] = $request->input('novel_sn','');
        if(empty($param['novel_sn'])){
            throw new IndexException(4020,'数据不存在');
        }

        $data = NovelLogic::getInstance()->getCooperateLink($param);
        return $this->endSuccess($data);
    }

    public function getDetail(Request $request):Response
    {
        $param = [];
        $param['novel_sn'] = $request->input('novel_sn','');
        if(empty($param['novel_sn'])){
            throw new IndexException(4020,'数据不存在');
        }

        $data = NovelLogic::getInstance()->getDetail($param);
        return $this->endSuccess($data);
    }

    public function getHotsSearchWord(Request $request)
    {
        $param = [];

        $data = NovelLogic::getInstance()->getHotsSearchWord($param);
        return $this->endSuccess($data);
    }

    public function getPlanIdAndPoints(Request $request):Response
    {
        $param = [];
        $param['novel_sn'] = $request->input('novel_sn');
        if(empty($param['novel_sn'])){
            throw new IndexException(4020,'推文不存在');
        }

        $data = NovelLogic::getInstance()->getPlanIdAndPoints($param);

        return $this->endSuccess($data);
    }

    public function createHinovelPassword(Request $request):Response
    {
        $param = [];
        $param['novel_sn'] = $request->input('novel_sn');
        if(empty($param['novel_sn'])){
            throw new IndexException(4020,'推文不存在');
        }

        $data = NovelLogic::getInstance()->createHinovelPassword($param);

        return $this->endSuccess($data);
    }
}